#ifndef STEELSERVERRESPONSE_H
#define STEELSERVERRESPONSE_H



#include<QObject>
#include<QHttpServer.h>
#include<QTimer>
#include<QJsonObject>
#include<QNetworkAccessManager>
#include<QHttpServer>

#include "src/Utils/defectlevelmap.h"
#include"src/Utils/jsonfilehelper.h"
#include "src/Thread/timerhandleseq.h"
#include "src/Thread/threadbase.h"
#include "src/CORPattern/handleinterface.h"
#include "src/Utils/inifilehelper.h"
#include "src/Utils/dbconnhelper.h"
#include "src/Sock/defectdatatcpclient.h"
//该类用于响应各个请求
class SteelServerResponse : public QObject
{
    Q_OBJECT
public:
    explicit SteelServerResponse(QObject *parent = nullptr);

    void startListen();


public:
    ///
    /// \brief 通过流水号获取当前钢卷数据
    ///
    void getSteelInfoBySeq(int);

    ///
    /// \brief 通过流水号获取各个相机的缺陷数据
    ///
    void getClientDefect(int,SteelInfo*);


    ///
    /// \brief 钢卷定级程序
    ///
    void getDetectSteelLevel(SteelInfo*);


    ///
    ///\brief 检测结束插入数据库和发送数据
    ///
    void onDetectFinish(SteelInfo *);

    ///
    ///\brief 转换steel对象到json中用于发送请求
    ///
    QJsonObject ParseSteelToJson(SteelInfo *steel);


    ///
    ///\brief 根据流水号和缺陷返回指定的缺陷总数
    ///
    int FindTotalCountByDefectName(QString defectName,int steelSequence);

    void AddSteelInfo(SteelInfo *steel);



public: //钢卷判级基础信息
    NormalDetectBase *normalDetect;
    VerticalLengthDetectBase *lengthDetect;
    FrequencyDetectBase *frequenceDetect;
    DirectLevelBase *directDetect;
    BesideDetectBase *besideDetect;

private:
    JsonFileHelper jsonHelper;
    IniFilehelper  InitHelper;

    QTimer *timer;
    TimerHandleSeq handleseq;

    SteelThread  *steelThread;
    ClientDefectThread  *threadClient;

    DefectOneHandle *oneHandle;
    DefectTwoHandle *twoHandle;
    DefectThreeHandle *threeHandle;


    SteelInfo *steel;


    //请求
    QNetworkAccessManager* manager;
    QHttpServer server;
    QJsonObject RequestObj;

    SteelInfo *LastSteel = nullptr;

    DbConnHelper dbhelper;

    //通信
    DefectDataTcpClient tcpClient;

    DefectLevelMap defectLevelMap;
signals:
};

#endif // STEELSERVERRESPONSE_H
